package component.global.utils
{
	import component.global.ComponentSetting;
	
	import flash.display.GradientType;
	import flash.display.Shape;

	public class GraphicsUtils
	{
		public static function createRectangle(width:int = ComponentSetting.SHAPE_DEFAULT_WIDTH, height:int = ComponentSetting.SHAPE_DEFAULT_HEIGHT, color:uint = ComponentSetting.SHAPE_COLOR):Shape
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(color);
			shape.graphics.drawRect(0,0,width,height);
			shape.graphics.endFill();
			return shape;
		}
		
		public static function createRoundRectangle(width:int = ComponentSetting.SHAPE_DEFAULT_WIDTH, height:int = ComponentSetting.SHAPE_DEFAULT_HEIGHT, radius:int = 10, color:uint = ComponentSetting.SHAPE_COLOR):Shape
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(color);
			shape.graphics.drawRoundRect(0,0,width,height,radius,radius);
			shape.graphics.endFill();
			return shape;
		}
		
		public static function createCheckBoxSelected(width:int = ComponentSetting.CHECK_BOX_DEFAULT_SIZE, height:int = ComponentSetting.CHECK_BOX_DEFAULT_SIZE):Shape{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(ComponentSetting.SHAPE_COLOR);
			shape.graphics.drawRect(0,0,width,height);
			shape.graphics.endFill();
			shape.graphics.lineStyle(2,0x000000);
			shape.graphics.moveTo(width * 1/5, height * 1/2);
			shape.graphics.lineTo(width * 3/7, height * 4/5);
			shape.graphics.lineTo(width * 5/6, height * 1/4);
			shape.y = 2;
			return shape;
		}
		
		public static function createArrowRectangle(width:int = ComponentSetting.ARROW_BUTTON_DEFAULT_SIZE, height:int = ComponentSetting.ARROW_BUTTON_DEFAULT_SIZE):Shape{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(ComponentSetting.SHAPE_COLOR);
			shape.graphics.drawRect(0,0,width,height);
			shape.graphics.beginFill(0x000000);
			shape.graphics.moveTo(width * 1/6, height * 3/4);
			shape.graphics.lineTo(width * 5/6, height * 3/4);
			shape.graphics.lineTo(width * 1/2, height * 1/4);
			shape.graphics.endFill();
			return shape;
		}
		
		public static function createCircle(radius:int = ComponentSetting.SHAPE_DEFAULT_RADIUS,colors:Array = null, ratios:Array = null):Shape{
			var shape:Shape = new Shape();
			if(colors == null){
				shape.graphics.beginFill(ComponentSetting.SHAPE_COLOR);
			} else {
				var alphas:Array = [];
				for (var i:int = 0; i < colors.length; i++)alphas.push(1);
				shape.graphics.beginGradientFill(GradientType.RADIAL,colors,alphas,ratios);
			}
			shape.graphics.drawCircle(0,0,radius);
			shape.graphics.endFill();
			shape.x = radius;
			shape.y = radius + 2;
			return shape;
		}
	}
}